package com.alu4r.atcrowdfunding.manager.service.impl;

import com.alu4r.atcrowdfunding.bean.Permission;
import com.alu4r.atcrowdfunding.manager.dao.PermissionMapper;
import com.alu4r.atcrowdfunding.manager.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    PermissionMapper permissionMapper;

    @Override
    public List<Permission> queryAllPermission() {
        List<Permission> list = permissionMapper.selectAll();
        return list;
    }

    @Override
    public boolean insertPermission(Permission permission) {
        try {
            permissionMapper.insert(permission);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public Permission getPermission(Integer id) {
        return permissionMapper.selectByPrimaryKey(id);
    }

    @Override
    public boolean updatePermission(Permission permission) {
        try {
            permissionMapper.updatePrimary(permission);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public boolean deletePermission(Integer id) {
        try {
            permissionMapper.deleteByPrimaryKey(id);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

    }

    @Override
    public List<Integer> queryPermissionIdByRoleId(Integer roleId) {

        return permissionMapper.queryPermissionIdByRoleId(roleId);
    }
}
